package com.yanqu.road.server.manger.union.listener;

import com.yanqu.road.entity.enums.eUnionSyncType;
import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.union.cross.CrossUnionModule;
import com.yanqu.road.server.manger.ICrossUnionSyncListener;
import com.yanqu.road.server.manger.config.HuntConfigMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;

import java.util.List;

public class ChamberPatronsChangeListener implements ICrossUnionSyncListener {

    @Override
    public void notifySync(int syncType, long playerId, CrossUnionInfo unionInfo, List<CrossUnionMember> memberList) {
        if(syncType == eUnionSyncType.ChamberPatrons.getValue()){
            //狩猎期间，下发商会
            if(!HuntConfigMgr.isHuntSystemOpenTime()){
                return;
            }
            if(!HuntConfigMgr.isInHuntBattleTime()){
                return;
            }
            for (CrossUnionMember member : memberList) {
                if(member.getServerId() != GameServer.getInstance().getServerId()){
                    continue;
                }
                GamePlayer gamePlayer = GamePlayerMgr.getOnlinePlayer(member.getUserId());
                if(gamePlayer != null){
                    gamePlayer.getModule(CrossUnionModule.class).syncChamberPatronsList();
                }
            }
        }
    }
}
